#define _SVID_SOURCE  1
#include <header.h>
int main(int argc, char* argv[]){
	ARGS_CHECK(argc, 1);

	char *ip = "192.168.169.128";
	char *port = "8080";

	int net_fd = socket(AF_INET, SOCK_STREAM, 0);

	struct sockaddr_in client_addr;
	client_addr.sin_family = AF_INET;
	client_addr.sin_port = htons(atoi(port));
	client_addr.sin_addr.s_addr = inet_addr(ip);

	connect(net_fd, (struct sockaddr*)&client_addr, sizeof(client_addr));

	char fileName[60] = {0};
	recv(net_fd, fileName, sizeof fileName, 0);
	printf("fileName:%s\n", fileName);

	/**
	 * @bug 粘包，读多了，把内容当成了文件名
	*/
	int file_fd = open(fileName, O_RDWR | O_CREAT, 0600);


	char buf[1024] = {0};
	recv(net_fd, buf, sizeof buf, 0);

	printf("buf:%s\n", buf);
	write(file_fd, buf, strlen(buf));


	close(net_fd);
	return 0;
}